<?php
function __autoload($class_name) 
{
    include $class_name . '.php';
}
$page = new page("Uprava clanku");
$content = '';
if(isset($_SESSION['user']) && 
        $_SESSION['user']->validate() && 
                ($_SESSION['user']->getRights() >= 2))
{
    //TODO:sprava clanku
    if(!isset($_GET['id']))
        header('location:articlesmanagement.php'); 
    $conn = new dbConnection();
    $query = 'SELECT * FROM articles WHERE id = '.$_GET['id'];
    $sql_result = $conn->db_query($query);
    $row = mysql_fetch_array($sql_result);
    $article = new article($row['id'],
    $row['id_author'],
    $row['id_section'],
    $row['date'],
    $row['counter'],
    $row['header'],
    $row['anotation'],
    $row['article'],
    $row['pending'],
    $row['note'],
    $row['state']);
    
    if(isset($_POST['editArticle']))
    {
        //uz je vyplnen
        $article->updateInfo(
            $_POST['id_section'],
            $_POST['header'],
            $_POST['anotation'],
            $_POST['text'],
            $_POST['note'],
            $_POST['state'],
            $_POST['pending']); 
        $content .= 'udaje byly zmeneny';
    }
    else
    {
    
        $to_change = array(
            new formText('id_section', 'id sekce: ', $article->__get('id_section')),

            new formTextArea('header','Nadpis: ', $article->__get('header')),
            new formTextArea('anotation','Anotace: ', $article->__get('anotation')),
            new formTextArea('text','Text: ', $article->__get('text')),
            new formTextArea('note','Poznamka: ', $article->__get('note')),
            new formTextArea('state','Stav: ', $article->__get('state')),
            new formTextArea('pending','Ceka na prijeti: ', $article->__get('pending')),
            new formSubmit('uloz zmeny')
            );


        $edit_article = new form(
        'editArticle',
        'editArticle.php?id='.$article->__get('id'),
        'post',
        'zmena clanku: ',
        $to_change);
        $content .= $edit_article->render();
    }
}else
{
    $content .= "Nemate dostatecna opravneni!";
        $content .= "<br />";        
}
echo $page($content);
?>
